
#include <iostream>
#include <vector>
#include <iomanip>
#define L vector<vector<LE>>
#define M vector<vector<ME>>
using namespace std;

struct ME {
    bool exist;
    double sp;
    double maxsp;
};

struct LE {
    int n;
    double sp;
    double maxsp;
};

L mtl(const M& m) {
    L l(m.size());
    for(int i=0; i<m.size(); i++) {
        for(int j=0; j<m[i].size(); j++) {
            if(m[i][j].exist) {
                l[i].push_back({j, m[i][j].sp, m[i][j].maxsp});
            }
        }
    }
    return l;
}

int main() {
    M m = {
        {{false,0,0}, {true,60,120}, {true,50,100}},
        {{true,70,80}, {false,0,0}, {false,0,0}},
        {{false,0,0}, {true,30,50}, {false,0,0}}
    };

    for(int i=0; i<m.size(); i++) {
        for(int j=0; j<m[i].size(); j++) {
            cout << boolalpha << setw(5) << m[i][j].exist << " "
                 << setw(4) << m[i][j].sp << " "
                 << setw(4) << m[i][j].maxsp << " | ";
        }
        cout << "\n";
    }

    cout << "\nmatrix_to_list:\n";
    L l = mtl(m);
    for (int i = 0; i < l.size(); i++) {
        cout << i;
        for (auto& e : l[i]) {
            cout << "->" << e.n << "(" << e.sp << "," << e.maxsp << ")";
        }
        cout << endl;
    }
    return 0;
}

